package course_work;

import java.util.List;
import java.util.ArrayList;

public class Neuron {
	private List<Double> weights;

	private int posX;
	private int posY;
	private int eLeft;
	private int eRight;
	private int eTop;
	private int eBottom;

	private String classTarget;

	public Neuron(int eLeft, int eRight, int eTop, int eBottom, int numWeights) {
		weights = new ArrayList<Double>();
		for (int i = 0; i < numWeights; i++) {
			weights.add(Math.random());
		}

		this.eLeft = eLeft;
		this.eRight = eRight;
		this.eTop = eTop;
		this.eBottom = eBottom;

		posX = (eLeft + eRight) / 2;
		posY = (eTop + eBottom) / 2;
	}

	public void setClassTarget(String str) {
		classTarget = str;
	}

	public String getClassTarget() {
		return classTarget;
	}

	public List<Double> getWeights() {
		return weights;
	}

	public int getX() {
		return posX;
	}

	public int getY() {
		return posY;
	}

	public double getDistance(List<Double> inputVector) {
		double distance = 0;

		for (int i = 0; i < inputVector.size(); i++) {
			distance += Math.pow(weights.get(i) - inputVector.get(i), 2);
		}
		return Math.sqrt(distance);
	}

	public void adjustWeight(List<Double> vector, double alpha, double influence) {
		for (int i = 0; i < weights.size(); i++) {
			double d = weights.get(i);
			double selisih = vector.get(i) - d;
			double tambahan = influence * alpha * selisih;
			d = d + tambahan;
			weights.set(i, d);
		}
	}
}